package com.xwj.exception.solution_3.demo.controller;

import com.xwj.common.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiaowajiang
 * @Date: 2022-04-04 22:17
 * @Description:
 **/
@Slf4j
@RestController
@Api(value = "DemoController", tags = "传统方式处理异常")
public class DemoController {

    @ApiOperation(value = "try catch 代码块", position = 2)
    @PostMapping("demo/exception/tryCatch")
    public R tryCatch(String bizCode) {
        try {
            log.info("tryCatch 入参：{}", bizCode);

            // do something
            return R.ok();
        } catch (Exception e) {
            log.error("业务执行失败，系统异常：{}", e.getMessage(), e);
            return R.error();
        }
    }

}
